<template>
  <div class="app-container">
    <div class="block">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input v-model="listQuery.name" size="mini" placeholder="请输入消息名称" />
        </el-col>
        <el-col :span="6">
          <el-button type="success" size="mini" icon="el-icon-search" @click.native="search">{{
            $t('button.search')
          }}</el-button>
          <el-button type="primary" size="mini" icon="el-icon-refresh" @click.native="reset">{{
            $t('button.reset')
          }}</el-button>
        </el-col>
      </el-row>
      <br>
      <el-row>
        <!-- <el-col :span="24">
          <el-button v-permission="['/msgReminder/add']" type="success" size="mini" icon="el-icon-plus"
            @click.native="add">{{ $t('button.add') }}</el-button>
        </el-col> -->
        <el-col :span="24">
          <el-button v-permission="['/msgReminder/add']" type="success" size="mini" icon="el-icon-plus" @click.native="addFrom">{{
            $t('button.add')
          }}</el-button>
        </el-col>
      </el-row>
    </div>

    <el-table v-loading="listLoading" :data="list" :header-cell-style="{ background: '#f5f5f7' }" element-loading-text="Loading" border fit highlight-current-row
      @current-change="handleCurrentChange">
      <el-table-column prop="name" label="消息名称">
      </el-table-column>

      <el-table-column prop="reminderName" label="消息参数">
      </el-table-column>

      <el-table-column prop="description" label="备注">

      </el-table-column>

      <el-table-column fixed="right" label="操作" width="240" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button v-permission="['/msgReminder/edit']" type="primary" size="mini" icon="el-icon-edit"
            @click="edit(row)">{{ $t('button.edit') }}</el-button>
          <el-button v-permission="['/msgReminder/delete']" type="danger" size="mini" icon="el-icon-delete" @click.native="remove(row)">{{ $t('button.delete') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 50, 100, 500]"
      :page-size="listQuery.pageSize" :total="total" @size-change="changeSize" @current-change="fetchPage"
      @prev-click="fetchPrev" @next-click="fetchNext" />

    <el-dialog :title="addFormTitle" :visible.sync="addFormVisible" width="70%">
      <el-form ref="addForm" :model="addForm" :rules="addFormRules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="消息名称" prop="name">
              <el-input v-model="addForm.name" minlength="1" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="消息参数" prop="reminderName">
              <el-input v-model="addForm.reminderName" minlength="1" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="description">
              <el-input v-model="addForm.description" minlength="1" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item>
          <el-button type="primary" @click="addSave">{{ $t('button.submit') }}</el-button>
          <el-button @click.native="addFormVisible = false">{{ $t('button.cancel') }}</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>


    <el-dialog :title="editFormTitle" :visible.sync="editFormVisible" width="75%">
      <el-form ref="editForm" :model="editForm" :rules="editFormRules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="消息名称" prop="name">
              <el-input v-model="editForm.name" minlength="1" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="消息参数" prop="reminderName">
              <el-input v-model="editForm.reminderName" minlength="1" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="description">
              <el-input v-model="editForm.description" minlength="1" />
            </el-form-item>
          </el-col>
          <el-col :span="24" >
            <el-form-item v-for="(rec, index) in editForm.templateChildren" :key="rec.index" :label="'模板内容'"
              :prop="'templateChildren.' + index + '.templateContent'" :rules="[
                {
                  required: true, message: '请输入模板内容', trigger: 'blur'
                },
              ]">
              <el-col :span="13">
                <el-input v-model="rec.templateContent" placeholder="模板内容">
                </el-input>
              </el-col>
              <el-col :span="4">&nbsp;&nbsp;
                <el-button type="danger" icon="el-icon-delete" @click.prevent="removeTemplateDetail(rec)">{{
                  $t('button.delete')
                }}</el-button>
              </el-col>
            </el-form-item>
          </el-col>
          <el-col :span="24" >
            <el-form-item v-for="(rec, index) in editForm.dictChildren" :key="rec.index" :label="'消息名称'"
              :prop="'dictChildren.' + index + '.dictName'" :rules="[
                {
                  required: true, message: '请输入消息名称', trigger: 'blur'
                },
              ]">
              <el-col :span="4">
                <el-input v-model="rec.dictName" placeholder="消息名称">
                </el-input>
              </el-col>
              <el-col :span="7">
                <el-form-item :label="'消息参数' + (index + 1)" :prop="'dictChildren.' + index + '.dictVaule'" :rules="{
                  required: true, message: '请输入消息参数', trigger: 'blur'
                }">
                  <el-input v-model="rec.dictVaule" placeholder="消息参数" />
                </el-form-item>
              </el-col>
           
              <el-col :span="8">
                <!-- <el-input v-model="rec.description" placeholder="描述" /> -->
                <el-form-item :label="'描述' ">
                  <el-input v-model="rec.description" placeholder="描述" />
                </el-form-item>
              </el-col>

              <el-col :span="4">&nbsp;&nbsp;
                <el-button type="danger" icon="el-icon-delete" @click.prevent="removeDictDetail(rec)">{{
                  $t('button.delete')
                }}</el-button>
              </el-col>
            </el-form-item>
          </el-col>
        
        </el-row>
        <el-form-item>
          <el-button type="primary" @click="editSave">{{ $t('button.submit') }}</el-button>
          <el-button     @click="addDictDetail">添加消息参数</el-button>
          <el-button     @click="addTemplateDetail">添加模板内容</el-button>
          <el-button @click.native="editFormVisible = false">{{ $t('button.cancel') }}</el-button>
        </el-form-item>
        

      </el-form>
    </el-dialog>
  </div>
</template>

<script src="./msgReminder.js"></script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
